package com.tdtxdcxm.ruralcommunity.appruntime;

import ohos.app.Context;
import ohos.data.DatabaseHelper;
import ohos.data.preferences.Preferences;

public class UserConfigInfo {
    public static boolean pushData(Context context,String[][] userpersoninfo){
        String usercfgfile = userpersoninfo[0][1]+".tdx";
        DatabaseHelper databaseHelper = new DatabaseHelper(context);
        Preferences preferences = databaseHelper.getPreferences(usercfgfile);

        for(int i = 0;i < userpersoninfo.length;i++){
            preferences.putString(userpersoninfo[i][0],userpersoninfo[i][1]);
        }
        return preferences.flushSync();
    }
    public static void pullData(Context context,String[] userpersoninfo){
        String usercfgfile = userpersoninfo[0]+".tdx";

        DatabaseHelper databaseHelper = new DatabaseHelper(context);
        Preferences preferences = databaseHelper.getPreferences(usercfgfile);

        DataCenterControl.age = preferences.getString("age", "-1岁");
        DataCenterControl.gender = preferences.getString("gender","未知");
    }
    public static void deleteUserInfo(Context context,String username){
        String usercfgfile = username+".tdx";
        DatabaseHelper databaseHelper = new DatabaseHelper(context);
        Preferences preferences = databaseHelper.getPreferences(usercfgfile);

        databaseHelper.deletePreferences(usercfgfile);
        databaseHelper.removePreferencesFromCache(usercfgfile);
    }

    public static Boolean compareData(Context context, String username, String searchkey, String comparevalue){
        String usercfgfile = username+".tdx";

        DatabaseHelper databaseHelper = new DatabaseHelper(context);
        Preferences preferences = databaseHelper.getPreferences(usercfgfile);

        if(preferences.getString(searchkey, "").equals(comparevalue)){
            return true;
        }

        return false;
    }
    private UserConfigInfo() {}
}
